package org.xgj.zhangben;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;

import com.opensymphony.xwork2.ActionInvocation;

/**
 * 
 * 重写了默认的chain拦截器com.opensymphony.xwork2.ActionChainResult
 * 可以正确跳转actionName!method这种DMI型式的路径 可以带参数跳转 使用: <struts> <package ...
 * <result-types> <result-type name="chain"
 * class="com.common.base.struts2.interceptor.ActionChainResult"></result-type>
 * </result-types> <result type="chain">...</result> </package> </struts>
 * 
 * @author Administrator
 * 
 */
@SuppressWarnings("unchecked")
public class ActionJumpResult extends StrutsResultSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8293683230811802395L;
	private String type = "inner";
	private String url;
	private String title = "";

	public void setType(String type) {
		this.type = type;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Override
	protected void doExecute(String locationArg, ActionInvocation invocation)
			throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		if (url == null) {
			url = locationArg;
		}
		//在当前页面跳转
		if ("inner".equalsIgnoreCase(type)) {
			request.setAttribute("jumpPageType", "inner");
		} else if ("outter".equalsIgnoreCase(type)) {
			request.setAttribute("jumpPageType", "outter");
		}
		request.setAttribute("jumpPage", url);
		request.setAttribute("title", title);
		RequestDispatcher dispatcher = request
				.getRequestDispatcher("/jump.jsp");
		dispatcher.forward(request, response);
	}

}